package vashion.azeroth.core.result;

public final class ApiResult<T> implements Result<T> {

	private static final long serialVersionUID = 652179543847865366L;

	private Integer errorCode;
	private String errorMsg;
	private boolean success = true;
	private T data;
	private Integer totalCount;
	private Long totalEsCount;

	public ApiResult() {

	}

	public static <T> ApiResult<T> newSuccessResult() {
		ApiResult<T> result = new ApiResult<T>();
		result.success = true;
		return result;
	}

	public static <T> ApiResult<T> newSuccessResult(T data) {
		ApiResult<T> result = new ApiResult<T>();
		result.success = true;
		result.setData(data);
		return result;
	}

	public static <T> ApiResult<T> newSuccessResult(T data, Integer totalCount) {
		ApiResult<T> result = new ApiResult<T>();
		result.success = true;
		result.setData(data);
		result.setTotalCount(totalCount);
		return result;
	}

	public static <T> ApiResult<T> newErrorResult(int errorCode, String errorMsg) {
		ApiResult<T> result = new ApiResult<T>();
		result.success = false;
		result.setErrorCode(errorCode);
		result.setErrorMsg(errorMsg);
		return result;
	}

	public static <T> ApiResult<T> newErrorResult(int errorCode,
			String errorMsg, T data) {
		ApiResult<T> result = new ApiResult<T>();
		result.success = false;
		result.setErrorCode(errorCode);
		result.setErrorMsg(errorMsg);
		result.setData(data);
		return result;
	}

	@Override
	public boolean isSuccess() {
		return success;
	}

	@Override
	public void setData(T data) {
		this.data = data;
	}

	@Override
	public void setSuccess(boolean success) {
		this.success = success;
	}

	@Override
	public T getData() {
		return data;
	}

	public Integer getErrorCode() {
		return errorCode;
	}

	public void setErrorCode(Integer errorCode) {
		this.errorCode = errorCode;
	}

	public String getErrorMsg() {
		return errorMsg;
	}

	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}

	public Integer getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(Integer totalCount) {
		this.totalCount = totalCount;
	}

	public Long getTotalEsCount() {
		return totalEsCount;
	}

	public void setTotalEsCount(Long totalEsCount) {
		this.totalEsCount = totalEsCount;
	}

}
